import java.util.Comparator;


public class PriceComparator implements Comparator<TradeOrder>
{
	private boolean asc;
	public PriceComparator()
	{
		asc = true;
	}
	public PriceComparator(boolean asc)
	{
		this.asc = asc;
	}
	public int compare(TradeOrder ord1, TradeOrder ord2) // still overrides superclass method because of generic specified above
	{
		if (ord1.isMarket() && ord2.isMarket())
			return 0;
		else if (ord1.isMarket() && ord2.isLimit())
			return -1;
		else if (ord1.isLimit() && ord2.isMarket())
			return 1;
		else if (asc)
			return (int)(Math.round(100*ord1.getPrice()) - Math.round(100*ord2.getPrice()));
		else
			return(int)(Math.round(100*ord2.getPrice()) - Math.round(100*ord1.getPrice()));
	}
}
